package com.glory.brepda.activity.mfg;

import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.glory.brepda.R;
import com.glory.brepda.base.BaseActivity;
import com.glory.brepda.callback.CustomDialogEntityCallBack;
import com.glory.brepda.entity.WaferEntity;
import com.glory.brepda.entity.response.BaseResponseBean;
import com.glory.brepda.utils.NetUtils;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.lzy.okgo.model.Response;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_EntityCallBack;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_LogUtils;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_StaticMembers;
import com.pda.platform.ui.ui_pdaplatform.view.FreeUI_ClearEditText;

import butterknife.BindView;

public class FixtureIssuingActivity extends BaseActivity {

    @BindView(R.id.llMain)
    LinearLayout llMain;
    @BindView(R.id.etFixtureCode)
    FreeUI_ClearEditText etFixtureCode;
    @BindView(R.id.tvTitle)
    TextView tvTitle;
    @BindView(R.id.tvBaseSubmit)
    TextView tvBaseSubmit;
    @Override
    protected int getLayoutResId() {
        return R.layout.activity_fixtureissuing;
    }

    @Override
    protected void initView() {
        setMainLayout(llMain);
        String title = getIntent().getStringExtra(FreeApi_StaticMembers.SHOW_PLUGIN_KEY);
        tvTitle.setText(title);
        tvBaseSubmit.setVisibility(View.GONE);
    }

    @Override
    protected void initData() {
        initEdit(etFixtureCode, s->{
            FreeUI_EntityCallBack<BaseResponseBean<Object>> callBack = new CustomDialogEntityCallBack<BaseResponseBean<Object>>
                    (new TypeToken<BaseResponseBean<Object>>() {
                    }.getType(), getSupportFragmentManager(), FixtureIssuingActivity.this) {

                @Override
                public void onSuccess(Response<BaseResponseBean<Object>> response) {
                    super.onSuccess(response);
                    if (response.body().isSuccess(FixtureIssuingActivity.this, true, getSupportFragmentManager())) {
                        showToast("发料成功",true);
                        etFixtureCode.setText("");
                        etFixtureCode.requestFocus();
                    }
                }

                @Override
                public void onError(Response<BaseResponseBean<Object>> response) {
                    super.onError(response);
                    etFixtureCode.requestFocus();
                    FreeApi_LogUtils.saveErrorMessages(response.getException(), "TOOLISSUE");
                }
            };
            JsonObject map = new JsonObject();
            map.addProperty("ACTIONTYPE", "ISSUE");
            map.addProperty("TOOLID", s);
            NetUtils.requestPostNet("IF.TOOLISSUE", "Common", FixtureIssuingActivity.this, map, callBack);

        });
    }
}
